package com.example.demo.controller;

import com.example.demo.pojo.PageResult;
import com.example.demo.pojo.Result;
import com.example.demo.pojo.dto.OrderPageDTO;
import com.example.demo.pojo.dto.OrderPayDTO;
import com.example.demo.pojo.dto.OrderSubmitDTO;
import com.example.demo.pojo.entity.Order;
import com.example.demo.pojo.vo.OrderSubmitVO;
import com.example.demo.pojo.vo.OrderVO;
import com.example.demo.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/polycystic/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @PostMapping("/submit")
    public Result<OrderSubmitVO> submit(@RequestBody OrderSubmitDTO orderSubmitDTO){
        OrderSubmitVO orderSubmitVO=orderService.submit(orderSubmitDTO);
        return Result.success(orderSubmitVO);
    }


    @PutMapping("/unPayment")
    public Result unPayment(@RequestBody OrderPayDTO orderPayDTO){
        orderService.unPayment(orderPayDTO);
        return Result.success();
    }

    @PutMapping("/payment")
    public Result payment(@RequestBody OrderPayDTO orderPayDTO){
        orderService.payment(orderPayDTO);
        return Result.success();
    }

    @GetMapping("/historyOrder")
    public Result<List<Order>> list(Integer status){
        List<Order> list=orderService.list(status);
        return Result.success(list);
    }

    @GetMapping("/orderDetail/{id}")
    public Result<OrderVO> getOrderInfo(@PathVariable Long id){
        OrderVO orderVO=orderService.getOrderInfo(id);
        return Result.success(orderVO);
    }

    @PutMapping("/cancel/{id}")
    public Result cancel(@PathVariable Long id,String cancelReason){
        orderService.cancel(id,cancelReason);
        return Result.success();
    }

    @GetMapping("/confirm")
    public Result confirm(Long id){
        orderService.confirm(id);
        return Result.success();
    }

    @GetMapping("/finish")
    public Result finish(Long id){
        orderService.finish(id);
        return Result.success();
    }


    @PostMapping("/page")
    public Result<PageResult> page(OrderPageDTO orderPageDTO){
        PageResult pageResult=orderService.page(orderPageDTO);
        return Result.success(pageResult);
    }

}
